package com.example.devsa_platform.common;

import com.example.devsa_platform.enums.ResultCode;
import lombok.Data;

import java.util.Optional;

@Data
public class Result <T> {
    private Integer code;
    private String msg;
    private T data;
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.code = ResultCode.RC200.getCode();
        result.msg = ResultCode.RC200.getMsg();
        result.data = data;
        return result;
    }

    public static <T> Result<T> fail(Integer code,String msg,T data){
        Result<T> result = new Result<>();
        result.code = Optional.ofNullable(code).orElse(ResultCode.RC100.getCode());
        result.msg = Optional.ofNullable(msg).orElse(ResultCode.RC100.getMsg());
        result.data = data;
        return result;
    }
}
